package com.base.controller;

import com.base.service.PayinfoesService;
import com.base.service.UsersService;
import com.base.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/admin")
public class content_chongzhikajilv {
    @Autowired
    PayinfoesService payinfoesService;

    @Autowired
    private UsersService usersService;

    /**
     *  @Date: 2019/9/30 9:51
     *  @Description:
     *  查询所有的纪录
     *  1话费卡/购物卡 2空中充值 3支付宝 4微信 5银联
     */
    @RequestMapping("/content_chongzhikajilv")
    public ModelAndView chongzhikajilv(HttpServletRequest request, Integer currentPageNo,
                              int type, String parentId,String time1,String time2,String mobile) {
        if (mobile==null||mobile.isEmpty()){
            mobile=null;
        }

        String adminUserId = (String) request.getSession().getAttribute("adminUserId");
        if (adminUserId.equals("7dd9a07e-9cef-4702-a165-b7033861c1b7")){
            adminUserId=null;
        }
        if (time1 == null || time2 == null || time1.equals("null") || time2.equals("null")) {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            //获取当前月第一天：
            Calendar c = Calendar.getInstance();
            c.add(Calendar.MONTH, 0);
            c.set(Calendar.DAY_OF_MONTH, 1);//设置为1号,当前日期既为本月第一天
            String first = format.format(c.getTime());
            time1 = first;
            System.out.println("===============first:" + first);

            //获取当前月最后一天
            Calendar ca = Calendar.getInstance();
            ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
            String last = format.format(ca.getTime());
            time2 = last;
            System.out.println("===============last:" + last);
        }
        Map<String, Object> map = new HashMap<>(); // 返回数据对象
        // 设置分页 获取内容
        Page page = new Page(); // 实例化分页
        if (currentPageNo != null) page.setCurrentPageNo(currentPageNo); // 设置当前页

        page.setRecordTotal(payinfoesService.countAllBytype( adminUserId, time1,time2, type, page,mobile)); // 设置总条数
        map.put("payinfoList", payinfoesService.selectAllBytype( adminUserId, time1,time2, type, page,mobile)); // 提现集合
        map.put("status", type); // 状态
        map.put("time1",time1);
        map.put("time2",time2);
        map.put("mobile",mobile);
        map.put("pages", page); // 分页
        return new ModelAndView("jsp/content_chongzhikajilv", map);
    }


}
